<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="/misc/css/base.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/btnicon.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/reset_admin.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/adminmenu.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/newadmin.css"  />
<script type="text/javascript" src="/misc/vendors/jquery/jquery_1.2.6.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js_build.js"></script>
<script type="text/javascript" >
var baseUrl = "<?=$themeUrl?>";
$().ready(function(){

});
var grids;
</script>
</head>
<style type="text/css">
.fieldtype_on{
background-color: #6262FF;
}
.forms{
display:none;
}
</style>
<body   style="background-color:#fcfcfc;">
<table class="tdashboard">
	<tr>
		<td width="250" style="vertical-align: top;">
    		<div style="padding:20px; padding-left:50px;">
    			<div style="padding: 5px;"><b>选择属性类型：</b></div>
					<div style="border: 1px solid #999999; width: 120px; line-height:20px;padding:2px;">
						<table style="width:100%;">
							<?php foreach ($field as $k=>$v):?>
							<tr onclick="fnSelField('<?php echo $k ?>')">
								<td style="width:20px;"><img src="<?php echo $v['img']?>" /></td>
								<td style="padding-left:5px; cursor: default;" class="fieldtype" id="fieldtype_<?php echo $k; ?>"><?php echo $v['text'];?></td>
							</tr>
							<?php endforeach;?>
						</table>
					</div>
    		</div>
		</td> 
         
		<td valign="top">
			<div style="padding-top:20px;">
				<div style="padding: 5px;">
					<b>属性详细信息：</b>
				</div>
    		<div style="padding-left:20px; line-height:28px;">
					<form id="form_char" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
							</tr>
							<tr>
								<td style="text-align: right;width:80px;">长度：</td>
								<td><input type="text" maxlength="3" value="" class="textBox" name="field_length" onkeyup="fnFCCN(this)" /></td>
							</tr>
						</table>
						<input type="hidden" name="field_type" value="char" />
						<input type="hidden" name="field_decimal_len" value="0" />
					</form>
					<form id="form_date" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
							</tr>
						</table>
						<input type="hidden" name="field_length" value="0" />
						<input type="hidden" name="field_type" value="date" />
						<input type="hidden" name="field_decimal_len" value="0" />
					</form>
					<form id="form_int" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
							</tr>
							<tr>
								<td style="text-align: right;width:80px;">长度：</td>
								<td><input type="text" maxlength="3" value="" class="textBox" name="field_length" onkeyup="fnFCCN(this)" /></td>
							</tr>
						</table>
						<input type="hidden" name="field_type" value="int" />
						<input type="hidden" name="field_decimal_len" value="0" />
					</form>
					<form id="form_float" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
							</tr>
							<tr>
								<td style="text-align: right;width:80px;">长度：</td>
								<td><input type="text" maxlength="3" value="" class="textBox" name="field_length" onkeyup="fnFCCN(this)" /></td>
							</tr>
							<tr>
								<td style="text-align: right;width:80px;">小数位：</td>
								<td><input type="text" maxlength="3" value="" class="textBox" name="field_decimal_len" onkeyup="fnFCCN(this)" /></td>
							</tr>
						</table>
						<input type="hidden" name="field_type" value="float" />
					</form>
					<form id="form_per" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
							</tr>
						</table>
						<input type="hidden" name="field_length" value="0" />
						<input type="hidden" name="field_type" value="per" />
						<input type="hidden" name="field_decimal_len" value="0" />
					</form>
					<form id="form_slt" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
								<td> </td>
							</tr>
							<tr>
								<td style="text-align: right; width:80px;">选择列表值：</td>
								<td>
									<textarea class="textBox" style="width:130px; height:80px;" name="field_option_val"></textarea>
								</td>
								<td>
									<div style="padding-left:10px;">
										<div style="padding: 5px; width: 150px; height: 160px; border: 1px solid #999999; background-color: #F8F8D1;">
											<div style="line-height:20px;"><b>提示：</b><br />
												例如，“优先级”选择列表框应该按顺序输入值，如下所示：<br />
												<select disabled="disabled" multiple="multiple" style="width: 50px;"><option>低</option><option>中</option><option>高</option></select>
											</div>
										</div>
									</div>
								</td>
							</tr>
						</table>
						<input type="hidden" name="field_length" value="0" />
						<input type="hidden" name="field_type" value="slt" />
						<input type="hidden" name="field_decimal_len" value="0" />
					</form>
					<form id="form_mslt" class="forms" action="" method="post" onsubmit="return false" >
						<table >
							<tr>
								<td style="text-align: right; width:80px;">属性名称：</td>
								<td><input type="text" maxlength="20" value="" class="textBox" name="field_name" /></td>
								<td> </td>
							</tr>
							<tr>
								<td style="text-align: right; width:80px;">选择列表值：</td>
								<td>
									<textarea class="textBox" style="width:130px; height:80px;" name="field_option_val"></textarea>
								</td>
								<td>
									<div style="padding-left:10px;">
										<div style="padding: 5px; width: 150px; height: 160px; border: 1px solid #999999; background-color: #F8F8D1;">
											<div style="line-height:20px;"><b>提示：</b><br />
												例如，“优先级”选择列表框应该按顺序输入值，如下所示：<br />
												<select disabled="disabled" multiple="multiple" style="width: 50px;"><option>低</option><option>中</option><option>高</option></select>
											</div>
										</div>
									</div>
								</td>
							</tr>
						</table>
						<input type="hidden" name="field_length" value="0" />
						<input type="hidden" name="field_type" value="mslt" />
						<input type="hidden" name="field_decimal_len" value="0" />
					</form>
			 </div>
		 </div>
	 </td>
	</tr>
	<tr><td style="text-align: center;" colspan="2"><br /><button onclick="fnSaveAll()">保存</button> <button onclick="parent.ymPrompt.close();">取消</button></td></tr>
</table>

<script type="text/javascript">  
var field = <?php echo json_encode($field); ?>;
var rs_who = <?=json_encode($rs_who)?>;
var url_save = "/admin_field/addsave";

var nowtypes = 'char';
$().ready(function(){
	//默认选择
	fnSelField('char');
});

/*选择字段*/
function fnSelField(t)
{
	nowtypes = t;
	$('.fieldtype').removeClass('fieldtype_on');
	$('#fieldtype_'+t).addClass('fieldtype_on');
	
	$('.forms').hide();
	$('#form_'+t).show();
}

/*保存*/
function fnSaveAll()
{
	var form = serializeObj("#form_"+nowtypes);
//	debug(form);
//	return false;
	/* string field_name=
string field_length=
string field_type=char
string field_decimal_len=0 */
	if(form.field_name == ''){
		alert('请填写属性名称');
		return false;
	}
	switch(nowtypes){
		case "char":
			if(form.field_length == ''){
				alert('请填写长度');
				return false;
			}
			if (parseInt(form.field_length, 10) == 0){
				alert('长度必须大于0');
				return false;
			}
			break;
		case "int":
			if(form.field_length == ''){
				alert('请填写长度');
				return false;
			}
			if (parseInt(form.field_length, 10) == 0){
				alert('长度必须大于0');
				return false;
			}
			break;
		case "float":
			if(form.field_length == ''){
				alert('请填写长度');
				return false;
			}
			if (parseInt(form.field_length, 10) == 0){
				alert('长度必须大于0');
				return false;
			}
			if(form.field_decimal_len == ''){
				alert('请填写小数位');
				return false;
			}
			if (parseInt(form.field_decimal_len, 10) == 0){
				alert('小数位必须大于0');
				return false;
			}
			break;
		case "slt":
			if(form.field_option_val == ''){
				alert('请填写选择列表值');
				return false;
			}
			break;
		case "mslt":
			if(form.field_option_val == ''){
				alert('请填写选择列表值');
				return false;
			}
			break;
	}
 
	$.post(
		url_save,
		{
			form:JSON.encode(form),
			who:rs_who.id
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success=='1'){ 
				alert('保存成功。');
				parent.ymPrompt.close();
				parent.window.location.reload();
			}
		}
	); 
}

 
</script>
</body>
</html>